/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 *
 * @author IT-Mafia
 */
@Entity
@Table(name = "rbh_risk_sub_cause")
@XmlRootElement
public class SubCause implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "SUB_CAUSE_ID", unique = true, nullable = false, columnDefinition = "smallint UNSIGNED")
    private Short subCauseId;
    @Column(name = "SUB_CAUSE_DESCRIPTION", length = 1024)
    private String subCauseDescription;
    @Basic(optional = false)
    @Column(name = "SUB_CAUSE_NAME", nullable = false, length = 100)
    private String subCauseName;
    @Basic(optional = false)
    @Column(name = "SUB_CAUSE_ORDER_NUMBER", columnDefinition = "tinyint UNSIGNED default 0", nullable = false)
    private short subCauseOrderNumber;
    @Basic(optional = false)
    @Column(name = "SUB_CAUSE_STATUS", columnDefinition = "boolean default true", nullable = false)
    private boolean subCauseStatus;
    @JoinColumn(name = "RBH_RISK_MAIN_CAUSE", referencedColumnName = "MAIN_CAUSE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private MainCause mainCause;
    @OneToMany(mappedBy = "subCause", fetch = FetchType.LAZY)
    @Cascade({CascadeType.DETACH})
    private List<RiskData> riskDataList;

    public SubCause() {
    }

    public SubCause(Short subCauseId) {
        this.subCauseId = subCauseId;
    }

    public SubCause(Short subCauseId, String subCauseName, short subCauseOrderNumber, boolean subCauseStatus) {
        this.subCauseId = subCauseId;
        this.subCauseName = subCauseName;
        this.subCauseOrderNumber = subCauseOrderNumber;
        this.subCauseStatus = subCauseStatus;
    }

    public Short getSubCauseId() {
        return subCauseId;
    }

    public void setSubCauseId(Short subCauseId) {
        this.subCauseId = subCauseId;
    }

    public String getSubCauseDescription() {
        return subCauseDescription;
    }

    public void setSubCauseDescription(String subCauseDescription) {
        this.subCauseDescription = subCauseDescription;
    }

    public String getSubCauseName() {
        return subCauseName;
    }

    public void setSubCauseName(String subCauseName) {
        this.subCauseName = subCauseName;
    }

    public short getSubCauseOrderNumber() {
        return subCauseOrderNumber;
    }

    public void setSubCauseOrderNumber(short subCauseOrderNumber) {
        this.subCauseOrderNumber = subCauseOrderNumber;
    }

    public boolean getSubCauseStatus() {
        return subCauseStatus;
    }

    public void setSubCauseStatus(boolean subCauseStatus) {
        this.subCauseStatus = subCauseStatus;
    }

    public MainCause getMainCause() {
        return mainCause;
    }

    public void setMainCause(MainCause mainCause) {
        this.mainCause = mainCause;
    }

    @XmlTransient
    public List<RiskData> getRiskDataList() {
        return riskDataList;
    }

    public void setRiskDataList(List<RiskData> riskDataList) {
        this.riskDataList = riskDataList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (subCauseId != null ? subCauseId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SubCause)) {
            return false;
        }
        SubCause other = (SubCause) object;
        if ((this.subCauseId == null && other.subCauseId != null) || (this.subCauseId != null && !this.subCauseId.equals(other.subCauseId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.rbh.risk.entity.SubCause[ subCauseId=" + subCauseId + " ]";
    }
}
